import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex);
const CancelToken = axios.CancelToken;

const wSize = {
  namespaced: true,
  state: {
    width: 0,
    height: 0
  },
  getters: {
    isMob(state) {
      return state.width <= 768;
    }
  },
  mutations: {
    UPDATE_WINDOW_SIZE(state, payload) {
      state.width = payload.width;
      state.height = payload.height;
    }
  }
};

export default new Vuex.Store({
  state: {
    source: CancelToken.source() // 存放axios的取消令牌
  },
  mutations: {
    setSource(state, obj) {
      state.source = obj // 路由切换是新建取消令牌，并写入store
    }
  },
  actions: {},
  modules: {wSize}
})
